<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>设置</title>
    <!--框架必需start-->
    <script type="text/javascript" src="../../libs/js/jquery.js"></script>
    <script type="text/javascript" src="../../libs/js/language/cn.js"></script>
    <script type="text/javascript" src="../../libs/js/framework.js"></script>
    <link href="../../libs/css/import_basic.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" id="skin" prePath="../../"/>
    <link rel="stylesheet" type="text/css" id="customSkin"/>
    <!--框架必需end-->
    <link rel="stylesheet" type="text/css" href="../../sample_skin/demo/style/style.css"/>

    <script src="../../libs/js/table/quiGrid.js" type="text/javascript"></script>

    <!--基本选项卡start-->
    <script type="text/javascript" src="../../libs/js/nav/basicTab.js"></script>
    <!--基本选项卡end-->

    <!--self开始-->
    <link rel="stylesheet" href="../../assets/css/m_style.css" class="m_style">
    <style>
        #_DialogButtons_0fk{
            text-align: center;
        }
        #_ButtonCancel_0fk{
            display: none;
        }
    </style>
    <!--self结束-->
</head>

<body>
<div class="m_pos">
    <img src="../../assets/images/position.png" alt="" class="m_position">
    <span>当前页面：</span>
    <span class="m_pos_lo">设置></span>
    <span class="m_pos_local">人员管理</span>
</div>
<div class="page_content">
    <div class="infoCard infoCard2">
           <div class="m_add"onclick="set_add()">新增</div>
            <div id="dataBasic" style="margin-top: 10px"></div>
    </div>
</div>

<script type="text/javascript">
    var ctx="http://www.chinalightning.com.cn/api/search_alluser/";
    //列表显示
    var gridData = {
        "form.paginate.pageNo": 1
    }
    $(function () {
        $.get(ctx,function (res) {
            if (res.message==200)
                gridData.rows=res.user;
            initComplete1();
        });
    });


    function initComplete1() {
        $("#dataBasic").quiGrid({
            columns: [{
                display: '员工ID',
                name: 'Customers_Company_Employees_ID',
                width: "4%"
            }, {
                display: '姓名',
                name: 'name',
                width: "6%",
            }, {
                display: '用户名',
                name: 'Customers_company_employee_name',
                width: "8%",
            }, {
                display: '权限',
                name: 'Administrator_type',
                width: "8%",
            }, {
                display: '性别',
                name: 'Gender',
                width: "4%",
            }, {
                display: '电话',
                name: 'Cell_phone_number',
                width: "10%",
            }, {
                display: 'E-mail',
                name: 'Email_address',
                width: "13%",
            }, {
                display: '身份证号',
                name: 'ID_number',
                width: "13%",
            }, {
                display: '员工卡号',
                name: 'Employee_card_number',
                width: "7%",
            }, {
                display: '是否接收短信',
                name: 'is_note',
                width: "8%",
            }, {
                display: '更改权限',
                name: 'change',
                width: "8%",
                cellClick:true,
                render: function (rowdata, rowindex, value, column) {
                    var mainCon = $('<div></div>');
                    var con = $("<span class=\"m_change\">更改</span>");
                    mainCon.append(con);
                    return mainCon.html();
                }
            },
                {
                display: '操作',
                name: 'operation',
                width: "6%",
                render: function (rowdata, rowindex, value, column) {
                    var mainCon = $('<div></div>');
                    var con = $('<span class="m_del" onclick="delUser('+rowdata.Customers_Company_Employees_ID+')">删除</span>');
                    mainCon.append(con);
                    return mainCon.html();
                }
            }
            ],
            data: gridData,
            sortName: 'id',
            rownumbers: false,
            checkbox: false,
            height: '100%',
            width: "100%",
            pageSize: 10,
            percentWidthMode: true,
            onClickCell : function (rowdata, rowid, rowobj){
                change(rowdata);
            }
        });
    }

    function onAfterShowData(data) {

        $("#dataBasic").find(".popupMenu").each(function () {
            $(this).hover(function () {
                $(this).find(".popupMenu_con").show();
            }, function () {
                $(this).find(".popupMenu_con").hide();
            });
        })
    }


    // 更改权限
    function change(data){
        var  diag = new top.Dialog();
        diag.Title = "更改权限";
        diag.URL = '../../assets/html/set_change.html';
        diag.Width = 650;
        diag.Height = 120;
        diag.ShowButtonRow = true;
        diag.OkButtonText = "保 存";
        diag.CancelButtonText="取消 ";
        diag.ParamsObj=data;
        diag.OKEvent = function() {
            diag.innerFrame.contentWindow.updateData();
        };
        diag.show();
    }
    // 新增
    function set_add(data){
        var  diag = new top.Dialog();
        diag.Title = "新增";
        diag.URL = '../../assets/html/set_add.html';
        diag.Width = 650;
        diag.Height = 220;
        diag.ShowButtonRow = true;
        diag.OkButtonText = "保 存";
        diag.CancelButtonText="取消 ";
        diag.ParamsObj=data;
        diag.OKEvent = function() {
            diag.innerFrame.contentWindow.updateData();
        };
        diag.show();
    }

    function delUser(id){
      $.post("http://www.chinalightning.com.cn/api/remove_user/",{id},function (res) {
          if (res.message==200){
              top.Dialog.alert("删除成功");
              $.get(ctx,function (res) {
                  if (res.message==200)
                      gridData.rows=res.user;
                  initComplete1();
              });

          }


          else
              top.Dialog.alert("删除失败");
      })

    }


</script>
</body>

</html>
